/**
* @Title: warning_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*
* @Project HIMS-FWA
* @date 2014年10月27日 下午4:43:38
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('CaseSearchListCtrl', ['$scope','$state','$http','$modal','BaseURL','Modal','CaseAuditListService',
	                                      'FwaTabsetService','InsuranceService','AuditDictServices',
	                                function($scope,$state,$http,$modal,baseUrl,Modal,caseAuditListService,
	                                		fwaTabsetService,InsuranceService,AuditDictServices){
		
		
		
		$scope.addOnClick = function(){
			fwaTabsetService.selectTab('caseAudit.caseAuditAdd',null,false);
		}

		InsuranceService.initMedicalOrgInfoList("","","0").success(function(response){
            $scope.medicalOrgInfoList = response.medicalOrgList;
		});
		$scope.auditDictServices = AuditDictServices;
		AuditDictServices.initCodeListDatas(); 

        var cellTemplate = '<a  ng-click="operation(data);">查看</a>';
		$scope.columns = [
		{
			label : '案件号',
			map : 'caseCode',
			width : '15%',
			 cellTemplate:'<a  ng:bind="data.caseCode" '+
                 'ng-click="operation(data)"></a>'
		},
		{
			label : '机构名称',
			map : 'orgName',
			width : '20%'
		}, {
			label : '受理时间',
			map : 'auditDate',
			width : '10%'
		}, {
			label : '不合理费用',
			map : 'totalDeduction',
			width : '15%'
		}, {
			label : '告知时间',
			map : 'notifyDate',
			width : '10%'
		}, {
			label : '机构确认时间',
			map : 'receiveDate',
			width : '10%'
		}, {
			label : '案件状态',
			map : 'statusName',
			width : '10%'
		}, {
			label : '操作',
			map : 'operation',
			width : '10%',
			cellTemplate:cellTemplate}];


		$scope.operation = function(data){
			$state.go('caseDetailView.detail',{problemCode:data.relatedCode,caseCode:data.caseCode});
		}
		
        $scope.queryAuditCase = function(data){
        }
		
		$scope.onReset = function(){
            $scope.params.caseCode=null;
            $scope.params.orgName=null;
            $scope.params.auditDate={start:null,end:null};
            $scope.params.sourceType=null;
            $scope.params.doctorName=null;
            $scope.params.jobLicense=null;
            $scope.params.sbmitDate={start:null,end:null};
            $scope.params.caseStatus=null;
	        };

        $scope.currentPage = 1;
        var start = 0;
        $scope.limit = 20;
        $scope.params = {
            page:0,
            pageSize:20
        };

        //分页监听
        $scope.$on('pageTool.skipPage',function(e,v){
            $scope.currentPage = v;
            start = $scope.limit*(v-1);
            $scope.onSubmit(true);
        });


        /**
	     * 
	     **/
	    $scope.onSubmit = function(resetPage){
            
            if(resetPage == null || !resetPage){
	    		$scope.currentPage= 1;
	    		$scope.params.page = 0; 
	    	}else{
    			$scope.params.page = ($scope.currentPage - 1) * 20;
	    	}

            
	    	var fparam = $scope.params;
            if($scope.params.auditDate){
                var start = $scope.params.auditDate.start;
                var end = $scope.params.auditDate.end;
                fparam.beginDate = start;
                fparam.endDate = end;
            }
            if($scope.params.sbmitDate){
                var start = $scope.params.sbmitDate.start;
                var end = $scope.params.sbmitDate.end;
                fparam.start = start;
                fparam.end = end;
            }
	    	if(!angular.isUndefined(fparam.orgName) && fparam.orgName=='') { 
	    		fparam.orgName=null;
    		}          
	    	if(!angular.isUndefined(fparam.orgCode) && fparam.orgCode=='') { 
	    		fparam.orgCode=null;
    		}          
	    	if(!angular.isUndefined(fparam.doctorName) && fparam.doctorName=='') { 
	    		fparam.doctorName=null;
    		}        
	    	if(!angular.isUndefined(fparam.jobLicense) && fparam.jobLicense=='') { 
	    		fparam.jobLicense=null;
    		}        
	    	if(!angular.isUndefined(fparam.sourceType) && fparam.sourceType=='') { 
	    		fparam.sourceType=null;
    		}        
	    	if(!angular.isUndefined(fparam.problemCode) && fparam.problemCode=='') { 
	    		fparam.problemCode=null;
	    	} 
	    	caseAuditListService.queryCaseAuditList(fparam).success(function(rst){
	    		if(rst){
            		$scope.tableData =rst.root;
        			$scope.totalCount = rst.total;
	    		}
	    	});
	    }
	    $scope.onSubmit();
		
		

	
	}]);
})();
